// pages/group1/group1.js
var app = getApp();
var userlist = [{headimg:'https://www.juquduo.com/static/resourse/newar/下一步.png',username:'第一个'},
                {headimg:'https://www.juquduo.com/static/resourse/newar/下一步.png',username:'第二个'},
                {headimg:'https://www.juquduo.com/static/resourse/newar/下一步.png',username:'第三个'},
                {headimg:'https://www.juquduo.com/static/resourse/newar/下一步.png',username:'第四个'},
                {headimg:'https://www.juquduo.com/static/resourse/newar/下一步.png',username:'第二个'},
                {headimg:'https://www.juquduo.com/static/resourse/newar/下一步.png',username:'第三个'},
                {headimg:'https://www.juquduo.com/static/resourse/newar/下一步.png',username:'第五个'},];
var list = new Array

Page({
  /**
   * 页面的初始数据
   */
  data: {
    pername:app.globalData.userInfo.nickName,
    perimg:app.globalData.userInfo.avatarUrl,
    fenzu:true,
    grouplist:false,
    groupid:'',
    groupmsg:true,
    sbox:app.globalData.winwidth/10,
    boxhei:app.globalData.winheight/2-50,
    userlist:[],
    shiliebiao:true,
    imagepath:'https://www.juquduo.com/static/resourse/yeshou/头像-1.png',
    username:'',
    headimg:''
  },

  onLoad: function (options) {
    var that = this
    // console.log(touxiang)
    // var user = {'username':options.name,
    //             'headimg':options.headimg}
    // list.push(user)
    // that.setData({userlist:list})
    wx.setNavigationBarTitle({
      title: '分组',
     })
    var openid = wx.getStorageSync('openid')
    // 页面第一次显示，显示玩家列表
    wx.request({
      url: 'https://www.juquduo.com/juquduo/join_activity/show_company_users',
      data:{
        // activityId:options.id,
        activityId:'192',
        openid:openid,
        // groupId:that.data.groupid
      },
      success(res){
        // console.log(res.data)

        // var newliea = []
        //   for (var i = 0; i < res.data.length; i++) {
        //     var Avatar = res.data[i].Avatar
        //     var NickName = res.data[i].NickName
        //     var Openid = res.data[i].OpenId
        //     var item = { Avatar: Avatar, NickName: NickName};
        //     if(Openid==openid){
        //       console.log('openid11111111111')
        //     }else{
        //       newliea = newliea.concat(item);
        //     }
        //   }
          // console.log(res)
            that.setData({
              // userlist: newliea
              userlist: res.data
            })
        // that.setData({userlist:res.data})
      }
    })
    // var shuzu = [
    //   "190/黄黄测试/3/1578528000/1",
    //   "188/黄黄测试/3/1578528000/1",
    //   "189/黄黄测试/3/1578528000/1"
    // ]
    // var one = shuzu[0].split("/")
    // console.log(one)

  },
  // 显示隐藏的分组框
  showgroup(){
    this.setData({grouplist:true})
  },
  groupbox(e){
    var that = this
    console.log(e.currentTarget.dataset.key+1)
    var groupid = e.currentTarget.dataset.key+1
    that.setData({groupid:groupid,fenzu:false,grouplist:false})
    var openid = wx.getStorageSync('openid')

    // 点击分组，显示分组信息
    wx.request({
      // url: 'https://www.juquduo.com/juquduo/activity/company/group_users',
      url: 'https://www.juquduo.com/juquduo/activity/group_players',
      data:{
        // activityId:options.id
        activityId:'192',
        openid:openid,
        groupId:that.data.groupid
      },
      success(res){
        console.log('分组信息')
        var msg = res.data[0][0]
        var other = res.data[1]
        console.log(other)
        that.setData({groupuser:msg,othlist:other})
      }
    })
  },
  
  zhuye(){
    wx.navigateTo({
      url: '../ayeshou/yeshou',
    })
  },
  
  // 刷新分组信息
  onPullDownRefresh() {
    // 下拉刷新
    var that = this;
    var openid = wx.getStorageSync('openid')
    wx.request({
      url: 'https://www.juquduo.com/juquduo/activity/company/group_users',
      data:{
        // activityId:options.id
        activityId:'192',
        openid:openid,
        groupId:that.data.groupid
      },
      success(res){
        console.log('分组信息')
        var msg = res.data[0][0]
        var other = res.data[1]
        console.log(other)
        that.setData({groupuser:msg,othlist:other})
      },
      complete: function () {
        // complete 
        wx.stopPullDownRefresh()
      }
    })
  },

})